﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PO_2011;

namespace WindowsFormsApplication1
{
    public partial class ContrastWindow : Form
    {
        private Pnm p;
        private Bitmap actualBitmap;
        public Form1 refToMainWindow;
        float value = 0;
        bool wasApply = false;

        public ContrastWindow(Pnm objectPnm, Bitmap bitmap)
        {
            InitializeComponent();
            p = objectPnm;
            actualBitmap = bitmap;
        }

        private void applyButton_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.BitmapTC;
            p.Bitmap = p.BitmapTC;
            wasApply = true;
            this.Close();
        }

        private void resetButton_Click(object sender, EventArgs e)
        {
            contrastTrackBar.Value = 100;
            this.contrastTrackBar_ValueChanged(sender, e);
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.CopyBitmap;
            this.Close();
        }

        private void ContrastWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!wasApply) this.refToMainWindow.pictureBox1.Image = p.CopyBitmap;
        }

        private void contrastTrackBar_ValueChanged(object sender, EventArgs e)
        {
            value = contrastTrackBar.Value;
            p.changeContrast(value, actualBitmap);
            this.refToMainWindow.pictureBox1.Image = p.BitmapTC;
        }



    }
}
